﻿namespace ysh.res
{
	using System.Windows.Media.Imaging;

	/// <summary>
	/// Gets the embedded resource image from the ysh.core assembly based on user provided file name with extension.
	/// Helper methods.
	/// </summary>
	public static class RescourceImage
	{
		#region public methods

		/// <summary>
		/// Gets the icon image from resource assembly.
		/// </summary>
		/// <param name="name"></param>
		/// <returns></returns>
		public static BitmapImage GetIcon(string name)
		{
			//Create the rescource reader stream.
			var stream = ResourceAssembly.GetAssembly().GetManifestResourceStream(ResourceAssembly.GetNamespace() + "Images.Icons." + name);
			var image = new BitmapImage();

			//Construct and return image.
			image.BeginInit();
			image.StreamSource = stream;
			image.EndInit();

			//Returns constructed BitmapImage.
			return image;
		}
		#endregion
	}
}
